<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>lesson 19</title>
    <script src="../dist/vue.js"></script>
  </head>
  <body>
    <div id="root"></div>
  </body>
  <script>
    // 动态组件: 根据数据的变化，结合 compoent 这个标签，来随时动态切换组件的现实
    // 异步组件: 是异步执行某些组件的逻辑，这叫做异步组件

    const counterComputedEffect = () => {
      const { ref, computed } = Vue;
      let counter = ref(0);
      let addConunterFive = computed({
        set(val) {
          counter.value = val - 5;
        },
        get() {
          return counter.value + 5;
        }
      });
      const handleConuter = () => {
        counter.value++;
      };

      setTimeout(() => {
        addConunterFive.value = 100;
      }, 3000);
      return { counter, addConunterFive, handleConuter };
    };

    const app = Vue.createApp({
      template: `
          <div>
            <div>
             计数器：<span>{{ counter }} - {{addConunterFive}}</span><button @click='handleConuter'>增加</button>
            </div>
          </div>
        `,
      setup(props, context) {
        return ({
          counter,
          addConunterFive,
          handleConuter
        } = counterComputedEffect());
      }
    });
    const vm = app.mount("#root");
  </script>
</html>
